<?php
/**
 * 模块启动文件
 */
namespace addons\member;
use addons\member\controllers\Index;
use system\Addon;

class Member extends Addon {
    public function getName()
    {
        return 'member';
    }

    public function getVersion()
    {
        return '1.0.0';
    }

    public function getAuthor()
    {
        return 'Colin';
    }

    public function getDesc()
    {
        return '基础的用户功能';
    }

    public function install()
    {
    	$sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@member`(
id int unsigned not null auto_increment primary key , 
nickname varchar(40) default null COMMENT '名称',
account varchar(50) not null comment '账户名' , 
pass varchar(50) null comment '密码' , 
platform tinyint(1) null default 1 comment '平台 1 WEB 2 H5 3 小程序' ,
avatar varchar(255) null default null comment '用户头像' , 
mobile varchar(11) null default null comment '手机号' , 
sex tinyint(1) null default 0 comment '性别 1男 2女 0未知',
create_time int(10) null default 0 comment '注册时间',
update_time int(10) null default 0 comment '最后登录时间',
version int(10) null default 0 comment '客户端版本号' , 
state tinyint(1) null default 0 comment '状态值 0 禁用 1 正常',
`money` decimal(10,2) default '0.00' COMMENT '金额',
`gold` int(11) default '0' COMMENT '金币数',
key a_s_p(`account`,`state`,`platform`),
key m_s_p(`mobile`,`state`,`platform`)
)engine=myisam charset=utf8 comment='用户表';";
		$sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@member_fields`(
uid int unsigned not null primary key , 
field varchar(100) default null COMMENT '字段名',
`value` varchar(255) not null comment '字段值' , 
key u_f(`uid`,`field`)
)engine=myisam charset=utf8 comment='用户扩展字段';";
		return $sql;
    }

    public function uninstall() {
		$sql['1.0.0'][] = "DROP TABLE `@member`;";
		$sql['1.0.0'][] = "DROP TABLE `@member_fields`;";
		return $sql;
	}

	public function onInitMenu(&$data = []){
		return [
			[
				'name'  => 'user',
				'title' => '会员管理',
				'icon'  => 'layui-icon-user',
				'list'  => [
					['name' => 'category', 'title' => '会员列表', 'auth_name' => Index::class, 'action' => 'index' , 'jump' => '---member/index'],
				]
			],
		];
	}
}